<template>
    <div :class="`order-detail-goods-item ${mode}`">
        <div class="goods-image">
            <img class="img-value" :src="imageSrc" alt="">
        </div>
        <div class="goods-info">
            <div>
                <div class="goods-name-and-price">
                    <div class="goods-name title-color">{{itemInfo.prod_name}}</div>
                    <div class="goods-price title-color"><span class="label">￥</span>{{itemInfo.price / 100}}</div>
                </div>
                <div class="goods-sku-and-count">
                    <div class="goods-sku">{{itemInfo.sku_name}}</div>
                    <div class="goods-count">x{{itemInfo.quantity}}</div>
                </div>
            </div>
            <div class="goods-action" v-if="isHaveAfterSale">
                <Button class="action-btn" size="small" @click="afterSaleAction">申请售后</Button>
            </div>
        </div>
    </div>
</template>

<script>
import { Button } from 'vant';
import { createShopImageSrc } from '@common/utils';
import ModeMixin from '@common/mixin';
export default {
    name: 'OrderDetailGoodsItem', // 详情单项
    mixins: [ModeMixin],
    components: {
        Button,
    },
    props: {
        itemInfo: {
            type: Object,
            default: () => {},
        },
        isHaveAfterSale: {
            type: Boolean,
            default: false,
        },
    },
    computed: {
        imageSrc() {
            const { itemInfo } = this.$props;
            return createShopImageSrc(itemInfo.pic);
        },
    },
    methods: {
        afterSaleAction() {
            // 跳转到售后
            this.$emit('afterSale', this.$props.itemInfo);
        },
    },
};
</script>

<style lang="less">
.order-detail-goods-item {
    .flex();
    .mode-white();
    .p-h(@shop-bag-gap);
    .p-v(@gap);
    .goods-image {
        width: 70px;
        height: 70px;
        border-radius: @border-radius;
        border: 1px solid rgba(125,125,131,0.2);
        .img-value {
            border-radius: @border-radius;
            width: 100%;
            height: 100%;
        }
    }
    &.black {
        .goods-info {
            .goods-action {
                .action-btn {
                    border-color: rgba(125, 125, 131, 0.7);
                    color: @tip-color;
                }
            }
        }
    }
    .goods-info {
        .flex-column();
        justify-content: space-between;
        .m-l(@shop-gap);
        flex: 1;
        .goods-name-and-price {
            .flex();
            justify-content: space-between;
            height: 20px;
            line-height: 20px;
            .goods-name {
                font-size: @font-size;
                color: @text-color;
                .text-overflow();
                width: 180px;
            }
            .goods-price {
                font-family: @font-family-number;
                font-size: @font-size-md;
                font-weight: 500;
                .label {
                    .m-r(-3);
                }
            }
        }
        .goods-sku-and-count {
            .flex();
            justify-content: space-between;
            color: @tip-color;
            font-size: @shop-font-size-sm;
            .m-t(@shop-gap-sm);
            .goods-sku {
                opacity: .7;
            }
        }
        .goods-action {
            .flex();
            justify-content: flex-end;
            .action-btn {
                height: 24px;
                line-height: 24px;
                border-radius: 22px;
                width: 70px;
                font-size: @font-size-sm;
                background-color: transparent !important;
            }
        }
    }
}
</style>
